<template>
  <div class="mod-config">
    <!--<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>-->
    <el-table
      :data="dataList"
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="userExtraId"
        header-align="center"
        align="center"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="extraName"
        header-align="center"
        align="center"
        label="师傅姓名">
      </el-table-column>
      <el-table-column
        prop="address"
        header-align="center"
        align="center"
        label="所属区域">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="身份证号">
      </el-table-column>
      <el-table-column
        prop="mobile"
        header-align="center"
        align="center"
        label="手机号">
      </el-table-column>
      <el-table-column
        prop="auditStatus"
        header-align="center"
        align="center"
        label="审核状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.auditStatus === 'AUDIT_FAILED'" size="small" type="danger">审核未通过</el-tag>
          <el-tag v-else-if="scope.row.auditStatus === 'VERIFIED'" size="small">已通过审核</el-tag>
          <el-tag v-else size="small">待审核</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="previewOrAuditHandle(scope.row.userExtraId,false)">预览</el-button>
          <el-button type="text" size="small" @click="previewOrAuditHandle(scope.row.userExtraId,true)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 预览 / 审核 -->
    <previewOrAudit v-if="previewOrAuditVisible" ref="previewOrAudit" @refreshDataList="getDataList"></previewOrAudit>
  </div>
</template>

<script>
  import previewOrAudit from './userExtra-preview-audit'

  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        auditOptions:[{
          value: 'TO_AUDIT',
          label: '待审核'
        },{
          value: 'VERIFIED',
          label: '审核通过'
        },{
          value: 'AUDIT_FAILED',
          label: '审核未通过'
        }],
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        previewOrAuditVisible: false
      }
    },
    components: {
      previewOrAudit
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/quickService/userExtra/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      //预览 / 审核
      previewOrAuditHandle (id,audit) {
        this.previewOrAuditVisible = true
        this.$nextTick(() => {
          this.$refs.previewOrAudit.init(id,audit)
        })
      }

    }
  }
</script>
